home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.25 / dynamic / dynamic_demo_eng.pas < prev    next >
Pascal/Delphi Source File  |  1995-04-23  |  28KB  |  648 lines

  1. {*******************************************************************}
  2. { DynamicLists V1.2                                                 }
  3. {*******************************************************************}
  4. { Een demonstratie hoe je met dynamic lists kunt werken.            }
  5. {*******************************************************************}
  6. { Door Hans Luyten                                                  }
  7. {                                                                   }
  8. { Compiler: HiSpeed Pascal v2.0 (Amiga)                             }
  9. {           (Works also with:  Turbo Pascal >v5.5  (MSDos)          }
  10. {                        and: HiSpeed Pascal >v2.4 (Atari))         }
  11. {           HiSpeed Pascal: (c) 1992 HiSoft                         }
  12. {           Turbo Pascal:   (c) 1991 Borland                        }
  13. {                                                                   }
  14. { Remark: VGAHi is also supported on Amiga and Atari HSPascal !!    }
  15. {                                                                   }
  16. { Compiler options: Range Check, Stack Check, I/O Check             }
  17. {                                                                   }
  18. {*******************************************************************}
  19. { Version: 1.0, 17 September 1993.                                  }
  20. {                                                                   }
  21. { Version: 1.1, 18 September 1993, Added:     Delete Node,          }
  22. {                                             Position Insert.      }            
  23. { Version: 1.2, 19 September 1993, Bug removed at 'Delete' and      }
  24. {                                 'positionInsert', also index-     }
  25. {                                 line for nodenumbering added.     }
  26. {*******************************************************************}
  27. PROGRAM DynamicLists;
  28.  
  29. uses
  30.   Graph,Crt;
  31. TYPE                                             { Onze LINKEDLIST  } 
  32.   StudentP    = ^StudentData;
  33.   StudentData = RECORD
  34.                   Naam   : string[10];
  35.                   ANr    : string[10];
  36.                   Next   : StudentP;
  37.                 END;
  38. CONST
  39.   CX      =  8;                                  { Karakter afstand }
  40.   CY      = 8;                                   { Regel afstand    }
  41.   FormH   = 20;                                  { Node Hoogte      }
  42.   FormW   = 95;                                  { Node Breedte     }      
  43.   Dist    =  5;                                  { Block afstand    }
  44.   MaxNodes= 5;                                   { Maximum Nodes    }
  45.  
  46. VAR 
  47.   StudentHead : StudentP;
  48.   VGAMode     : BOOLEAN;
  49.   c           : CHAR;
  50.   OldPalette  : PaletteType;
  51.   ActiveNodes : INTEGER;
  52.   
  53. {*******************************************************************}
  54. {************************* Alg-Procedures **************************}
  55. {*******************************************************************}
  56.  
  57. {*******************************************************************}
  58. { FixBar(x,y,x2,y2,Color1,Color2);                                  }
  59. { Vervangt SetColor, SetFillStyle en Bar in 1 procedure.            }
  60. {*******************************************************************}
  61. { PRE  : VGAMode                                                    }
  62. { POST : Bar getekend.                                              }
  63. {*******************************************************************}
  64. PROCEDURE FixBar(x,y,x2,y2 : INTEGER; color1, color2 : INTEGER);
  65. BEGIN
  66.   SetColor(Color1);
  67.   SetFillStyle(SolidFill,Color2);
  68.   Bar(x,y,x2,y2);
  69. END;
  70.  
  71. {*******************************************************************}
  72. { LeesInput(x,y,'Naam:',String);                                    }
  73. { Leest het keyboard tijdens grafisch scherm (ReadLn geeft probleem)}
  74. { van maximaal 10 tekens !                                          }
  75. {*******************************************************************}
  76. { PRE  : VGAMode=TRUE                                               }
  77. { POST : In String staat de input.                                  }
  78. {*******************************************************************}
  79. PROCEDURE LeesInput(x,y: INTEGER; header : String; 
  80.                     VAR TEXT : String);
  81. CONST
  82.   MaxLengte = 10;
  83. VAR
  84.   Letter : CHAR;
  85.   Teller : INTEGER;
  86. BEGIN
  87.   OutTextXY(x+CX,y+CY,header);
  88.   TEXT:='';
  89.   FOR Teller:=1 TO MaxLengte DO
  90.     BEGIN
  91.       Letter:=ReadKey;
  92.       IF ((Letter>CHR(31)) AND (Letter<CHR(127))) THEN
  93.         BEGIN                                 { Letters/Cijfers ?   }
  94.           TEXT:=concat(TEXT,Letter);          { Nieuwe letter erbij }
  95.           OutTextXY(x+CX*(Teller+6),y+CY,Letter);
  96.         END          
  97.       ELSE IF ((Letter=CHR(13)) OR (Letter=CHR(10))) THEN
  98.         exit                                  { RETURN = chr(13)    }
  99.       ELSE IF Letter=CHR(8) THEN
  100.         BEGIN                                 { Backspace = chr(8)  }
  101.           IF Teller>2 THEN
  102.             BEGIN
  103.               Teller:=Teller-2; { backspace + voorganger = 2 chars !}
  104.               delete(TEXT,Teller+1,1);        { verwijder laatste   }
  105.               FixBar(x+CX*(Teller+7),y+CY,x+CX*(Teller+8),y+2*CY,
  106.                      Yellow,Yellow);
  107.               SetColor(DarkGray);
  108.             END
  109.           ELSE
  110.             BEGIN
  111.               TEXT:='';                       { Alles wissen !!     }
  112.               Teller:=0;                      { = opnieuw invoeren  }
  113.               FixBar(x+CX*(Teller+7),y+CY,x+CX*(Teller+8),y+2*CX,
  114.                      Yellow,Yellow);
  115.               SetColor(DarkGray);
  116.             END;
  117.         END
  118.       ELSE 
  119.         Letter:=ReadKey;                      { Ctrl-codes opvangen }
  120.     END;
  121. END;
  122.  
  123. {*******************************************************************}
  124. {************************* GFX-Procedures **************************}
  125. {*******************************************************************}
  126.   
  127. {*******************************************************************}
  128. { OpenVGAScreen();                                                  }
  129. { Deze procedure zal proberen een VGAScherm te openen (600x480)     }
  130. { Tevens worden de gebruikte kleuren aangepast.                     }
  131. { Note: VGAHi wordt door HiSpeed Pascal (Amiga en Atari) en         }
  132. {       Turbo-Pascal (PC) simuleert/ondersteund !!                  }
  133. {*******************************************************************}
  134. { PRE  : De variabele VGAMode (boolean) moet geinitialiseerd        }
  135. {        zijn als globale variabele.                                }
  136. { POST : Als het VGA-scherm open is, is VGAMode=TRUE.               }
  137. {        Zoniet, dan is VGAMode=FALSE.                              }
  138. {*******************************************************************}
  139. PROCEDURE OpenVGAScreen;
  140. VAR
  141.   GfxDriver, DriverMode, ErrorCode : INTEGER;
  142. BEGIN
  143.   GfxDriver:=Detect;                             { Gfx mogelijk ?   }
  144.   InitGraph(GfxDriver,DriverMode,'');            { Gfx Init         }
  145.   SetGraphMode(VGAHi);                           { Probeer VGA ..   }
  146.   ErrorCode:=GraphResult;                        { VGA gelukt ??    }
  147.   IF ErrorCode=grOK THEN
  148.     VGAMode:=TRUE                                { VGA Gelukt...    }
  149.   ELSE
  150.     VGAMode:=FALSE;                              { Niks geen VGA !  }
  151.   IF VGAMode=TRUE THEN
  152.     BEGIN
  153.       GetPalette(OldPalette);                    { Actieve Palette  }
  154.       SetRGBPalette(Black   ,0 ,0 ,0 );          { opslaan en       }
  155.       SetRGBPalette(Blue    ,0 ,0 ,63);          { instellen voor   }
  156.       SetRGBPalette(Green   ,0 ,63,0 );          { correcte kleur-  }
  157.       SetRGBPalette(Red     ,63,0 ,0 );          { Palette.         }
  158.       SetRGBPalette(Yellow  ,63,63,0 );          { Ook voor Amiga,  }
  159.       SetRGBPalette(White   ,63,63,63);          { Atari en PC !!   }
  160.       SetRGBPalette(DarkGray,20,20,20);          { HIGHSPEED PASCAL }
  161.       SetColor(Yellow);
  162.       OutTextXY(180,470,'(C) 1993 By Hans Luyten. A-Yeah!');
  163.     END;  
  164. END;
  165.  
  166. {*******************************************************************}
  167. { RestoreColors;                                                    }
  168. { Herstelt oude palette... (als het goed is...)                     }
  169. {*******************************************************************}
  170. { PRE  : OldPalette moet de oude palette bevatten.                  }
  171. { POST : Oude Palette actief.                                       }
  172. {*******************************************************************}
  173. PROCEDURE RestoreColors;
  174. BEGIN
  175.   SetAllPalette(OldPalette);
  176. END;
  177.  
  178. {*******************************************************************}
  179. { DrawShadowBox(x,y,w,h);                                           }
  180. { Tekent een Shadowed-box.                                          }
  181. {*******************************************************************}
  182. { PRE  : VGAMode moet TRUE zijn (en dus geopend zijn!).             }
  183. { POST : Box op het sherm met schaduw rand.                         }
  184. {*******************************************************************}
  185. PROCEDURE DrawShadowBox(x,y,w,h:INTEGER);
  186. BEGIN
  187.   FixBar(x+3,y+3,x+w+3,y+h+3,DarkGray,DarkGray);  
  188.   FixBar(x,y,x+w,y+h,Yellow,Yellow);
  189. END;
  190.  
  191. {*******************************************************************}
  192. { DrawNodeBox(x,y);                                                 }
  193. { Tekent een NODE-Box voor de Linked-List.                          }
  194. {*******************************************************************}
  195. { PRE  : Heeft DrawShadowBox en VGAMode=TRUE nodig.                 }
  196. { POST : Een 3-delige box op het scherm.                            }
  197. {*******************************************************************}
  198. PROCEDURE DrawNodeBox(x,y: INTEGER);
  199. VAR
  200.   Teller : INTEGER;
  201. BEGIN
  202.   FOR Teller:=0 TO 2 DO
  203.     DrawShadowBox(x,y+(FormH+Dist)*Teller,FormW,FormH);
  204. END;
  205.  
  206. {*******************************************************************}
  207. { DrawPointer(x,y);                                                 }
  208. { Tekent een NODE-pointer voor de Linked-List (PIJL).               }
  209. {*******************************************************************}
  210. { PRE  : Heeft VGAMode=TRUE nodig.                                  }
  211. { POST : Pijl van Node n^.Next naar Node n+1^.Naam.                 }
  212. {*******************************************************************}
  213. PROCEDURE DrawPointer(x,y : INTEGER);
  214. BEGIN
  215.   y:=y+2*FormH+2*Dist+(FormH DIV 2);
  216.   x:=x+FormW-3*Dist;
  217.   SetColor(DarkGray);
  218.   SetFillStyle(SolidFill,DarkGray);
  219.   Circle(x,y,5);                                        { Cirkeltje }
  220.   SetColor(DarkGray);
  221.   FloodFill(x-3,y,DarkGray);                            { gevuld .. }
  222.   Bar(x+4,y-2,x+5*Dist,y+2);
  223.   Bar(x+5*Dist,y+2,x+5*Dist+4,y-2*FormH-2*Dist);
  224.   Bar(x+5*Dist+4,y-2*FormH-2*Dist,x+7*Dist,y-2*FormH-2*Dist+4);
  225.   PieSlice(x+8*Dist+4,y-2*FormH-2*Dist+2,138,215,10);
  226. END;
  227.  
  228. {*******************************************************************}
  229. { DrawMenu(x,y);                                                    }
  230. { Tekent option-menu (F1..F5).                                      }
  231. {*******************************************************************}
  232. { PRE  : Heeft DrawShadowBox en VGAMode=TRUE nodig.                 }
  233. { POST : Een Menu-Box voor de opties.                               }
  234. {*******************************************************************}
  235. PROCEDURE DrawMenu(x,y : INTEGER);
  236. BEGIN
  237.   DrawShadowBox(x,y,32*CX,17*CY);
  238.   SetColor(DarkGray);
  239.   OutTextXY(x+CX,y+CY,'Opties:');
  240.   OutTextXY(x+CX,y+3*CY, '1 Head Insertion Node');
  241.   OutTextXY(x+CX,y+5*CY, '2 Position Insertion Node');
  242.   OutTextXY(x+CX,y+7*CY, '3 Tail Insertion Node');
  243.   OutTextXY(x+CX,y+9*CY, '4 Remove Node');
  244.   OutTextXY(x+CX,y+11*CY,'5 Exit program');
  245.   OutTextXY(x+CX,y+15*CY,'(Max. 5 Nodes Allowed!)');
  246. END;
  247.  
  248. {*******************************************************************}
  249. { DrawNodeIndex;                                                    }
  250. { Tekent de balk met daarin de node nummering.                      }
  251. {*******************************************************************}
  252. { PRE  : VGAMode moet TRUE zijn, en de procedure DrawShadowBox      }
  253. {         moet aanwezig zijn.                                       }
  254. { POST : Een genummerde balk.                                       }
  255. {*******************************************************************}
  256. PROCEDURE DrawNodeIndex;
  257. BEGIN
  258.   DrawShadowBox(20,250,595,3*CX);
  259.   SetColor(DarkGray);
  260.   OutTextXY(20+CX ,250+CY,'[Number 1]');
  261.   OutTextXY(145+CX,250+CY,'[Number 2]');
  262.   OutTextXY(270+CX,250+CY,'[Number 3]');
  263.   OutTextXY(395+CX,250+CY,'[Number 4]');
  264.   OutTextXY(520+CX,250+CY,'[Number 5]');
  265. END;
  266.  
  267.   
  268. {*******************************************************************}
  269. {********************* DynamicList-Procedures **********************}
  270. {*******************************************************************}
  271.   
  272. {*******************************************************************}
  273. { EmptyList(StudentP);                                              }
  274. { Kijkt of een DynamischeLijst LEEG is. Een lege lijst is een lijst }
  275. { waarvoor nog geen 'new()' is gebruikt. StudentP wijst dus naar NIL}
  276. {*******************************************************************}
  277. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  278. { POST : De functie geeft TRUE als de lijst leeg is, FALSE als de   }
  279. {        lijst niet leeg is.                                        }
  280. {*******************************************************************}
  281. FUNCTION EmptyList(Student : StudentP):BOOLEAN;
  282. BEGIN
  283.   IF Student=NIL THEN
  284.     EmptyList:=TRUE                 { Head=NIL betekent: LEGE lijst }
  285.   ELSE
  286.     EmptyList:=FALSE;
  287. END;
  288.  
  289. {*******************************************************************}
  290. { InputStudent(x,y,StudentP);                                       }
  291. { Invoer van de data voor 'StudentP'.                               }
  292. {*******************************************************************}
  293. { PRE  : 'StudentP' moet geinitialiseerd zijn met new().            }
  294. {        en VGAMode=TRUE.                                           }
  295. { POST : 'StudentP' bevat de nieuwe data.                           }
  296. {*******************************************************************}
  297. PROCEDURE InputStudent(x,y : INTEGER;VAR Current : StudentP);
  298. BEGIN
  299.   SetColor(Yellow);
  300.   DrawShadowBox(x-CX,y-CY,23*CX,7*CY);
  301.   SetColor(DarkGray);
  302.   OutTextXY(x,y,'Input New node');
  303.   LeesInput(x,y+CY,'Name:',Current^.Naam);
  304.   LeesInput(x,y+3*CY,'ANr :',Current^.ANr);
  305.   FixBar(x-Cx,y-3*CY,x+22*CX+Dist,y+6*CY+Dist,Black,Black);
  306. END;
  307.  
  308. {*******************************************************************}
  309. { OutputStudent(x,y,StudentP);                                      }
  310. { Weergave van de data die in de node 'StudentP' staat.             }
  311. {*******************************************************************}
  312. { PRE  : 'StudentP' moet geinitialiseerd zijn met new() en mag niet }
  313. {        leeg zijn.                                                 }
  314. { POST : De inhoud van StudentP op het scherm.                      }
  315. {*******************************************************************}
  316. PROCEDURE OutputStudent(x,y : INTEGER; Current : StudentP);
  317. BEGIN
  318.   DrawNodeBox(x,y);
  319.   SetColor(DarkGray);
  320.   OutTextXY(x+CX,y+CY,Current^.Naam);
  321.   OutTextXY(x+CX,y+CY+FormH+Dist,Current^.ANr);
  322.   IF Current^.Next=NIL THEN
  323.     OutTextXY(x+CX,Y+CY+2*FormH+2*Dist,'NIL')
  324.   ELSE
  325.     DrawPointer(x,y);
  326. END;
  327.  
  328. {*******************************************************************}
  329. { GotoEnd(StudentP);                                                }
  330. { Maakt van 'StudentP' de pointer naar de laatste node. Let dus op! }
  331. {*******************************************************************}
  332. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  333. {         De lijst mag ook NIET leeg zijn !                         }
  334. { POST : 'StudenP' wijst nu naar de LAATSTE node in de lijst.       }
  335. {*******************************************************************}
  336. PROCEDURE GotoEnd(VAR Position : StudentP);
  337. BEGIN
  338.   WHILE Position^.Next<>NIL DO        { Laatste Node wijst naar NIL }
  339.     Position:=Position^.Next;
  340. END;
  341.  
  342. {*******************************************************************}
  343. { GotoNodeNr(n,StudentP);                                           }
  344. { Maakt van 'StudentP' de pointer naar de n-de node. Let dus op!    }
  345. {*******************************************************************}
  346. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  347. {         De lijst mag ook NIET leeg zijn !                         }
  348. { POST : 'StudenP' wijst nu naar de n-de node in de lijst.          }
  349. {*******************************************************************}
  350. PROCEDURE GotoNodeNr(n : INTEGER; VAR Position : StudentP);
  351. VAR
  352.   Teller : INTEGER;
  353.   Temp   : StudentP;
  354. BEGIN
  355.   Position:=StudentHead;
  356.     FOR Teller:=2 TO n DO        { StudentHead is global 1e node !! }
  357.     BEGIN
  358.        IF Position^.Next<>NIL THEN { Laatste Node wijst naar NIL !! }
  359.       Position:=Position^.Next;
  360.     END;
  361. END;
  362.  
  363. {*******************************************************************}
  364. { HeadInsert(x,y,StudentP);                                         }
  365. { Initialiseerd indien nodig de lijst en voegt aan de kop van de    }
  366. { lijst een nieuwe node toe.                                        }
  367. {*******************************************************************}
  368. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  369. { POST : De lijst is 1 node langer geworden, aan de kop !           }
  370. {*******************************************************************}
  371. PROCEDURE HeadInsert(x,y : INTEGER; VAR Head : StudentP);
  372. VAR
  373.   Node  : StudentP;
  374.   Empty : BOOLEAN;
  375. BEGIN
  376.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  377.   IF Empty THEN
  378.     BEGIN
  379.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  380.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  381.     END
  382.   ELSE
  383.     NEW(Node);                   { Er wordt een 'node' toegevoegd   }
  384.   InputStudent(x,y,Node);        { Invoer data van de node          }
  385.   IF Empty THEN
  386.     Node^.Next:=NIL
  387.   ELSE
  388.     BEGIN
  389.       Node^.Next:=Head;          { Vooraan schuiven van de node     }
  390.       Head:=Node;
  391.     END;
  392. END;
  393.  
  394. {*******************************************************************}
  395. { PositionInsert(x,y,StudentP);                                     }
  396. { Initialiseerd indien nodig de lijst en plaatst op POS een nieuwe  }
  397. { node in de lijst. Doet OOK position insert als: -de lijst leeg is }
  398. {                                                 -Maar 1 node heeft}
  399. {*******************************************************************}
  400. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  401. { POST : De lijst is 1 node langer geworden.                        }
  402. {*******************************************************************}
  403. PROCEDURE PositionInsert(x,y : INTEGER; VAR Head : StudentP);
  404. VAR
  405.   Node     : StudentP;
  406.   Position : StudentP;
  407.   Empty    : BOOLEAN;
  408.   Invoer   : string[15];
  409.   Nr       : INTEGER;
  410.   
  411. BEGIN
  412.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  413.   IF Empty THEN
  414.     BEGIN
  415.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  416.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  417.       Node^.Next:=NIL;           { eerste en laatse Node            }
  418.     END
  419.   ELSE IF ActiveNodes<2 THEN
  420.     BEGIN
  421.       NEW(Node);
  422.       Head^.Next:=Node;
  423.       Node^.Next:=NIL;
  424.     END 
  425.   ELSE IF ActiveNodes>1 THEN
  426.     BEGIN
  427.       NEW(Node);                  { Er wordt een 'node' toegevoegd  }
  428.       Position:=Head;
  429.       Invoer:='Position number [1-';
  430.       Invoer:=ConCat(Invoer,CHR(48+ActiveNodes),']: ');
  431.       REPEAT                      { Read 1-ActiveNodes (max=5)      }
  432.         SetColor(Yellow);
  433.         SetFillStyle(SolidFill,Yellow);
  434.         DrawShadowBox(x-CX,y-CY,23*CX,3*CY);
  435.         SetColor(DarkGray);
  436.         OutTextXY(x,y,Invoer);
  437.         c:=readKey;
  438.       UNTIL ((c>#48)AND(c<CHR(48+ActiveNodes+1)));
  439.       Nr:=ORD(c)-48;    
  440.       GotoNodeNr(Nr-1,Position);  { Add after n-1                   }
  441.     END;
  442.   InputStudent(x,y,Node);         { Invoer data van de node         }
  443.   IF (NOT(Empty)AND(ActiveNodes>1)) THEN
  444.     BEGIN  
  445.       Node^.Next:=Position^.Next;
  446.       Position^.Next:=Node;
  447.     END
  448.   ELSE IF Empty THEN
  449.     Head:=Node;
  450. END;
  451.  
  452. {*******************************************************************}
  453. { TailInsert(x,y,StudentP);                                         }
  454. { Initialiseerd indien nodig de lijst en voegt aan de staart van de }
  455. { lijst een nieuwe node toe.                                        }
  456. {*******************************************************************}
  457. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  458. { POST : De lijst is 1 node langer geworden, aan de staart !        }
  459. {*******************************************************************}
  460. PROCEDURE TailInsert(x,y : INTEGER; VAR Head : StudentP);
  461. VAR
  462.   Node  : StudentP;
  463.   Tail  : StudentP;
  464.   Empty : BOOLEAN;
  465. BEGIN
  466.   Empty:=EmptyList(Head);        { Kijk of de lijst leeg is         }
  467.   IF Empty THEN
  468.     BEGIN
  469.       NEW(Head);                 { Lege lijst wordt geinitialiseerd }
  470.       Node:=Head;                { Nieuw node = head, bij lege lijst}
  471.     END
  472.   ELSE
  473.     BEGIN
  474.       NEW(Node);                 { Er wordt een 'node' toegevoegd   }
  475.       Tail:=Head;
  476.       GotoEnd(Tail);
  477.     END;
  478.   InputStudent(x,y,Node);        { Invoer data van de node          }
  479.    Node^.Next:=NIL;
  480.   IF NOT(Empty) THEN
  481.     Tail^.Next:=Node             { Achteraan schuiven van de node   }
  482.   ELSE
  483.     Head:=Node;
  484. END;
  485.  
  486. {*******************************************************************}    
  487. { ShowList(x,y,StudentP);                                           }
  488. { Laat alle nodes in een lijst zien, te beginnen bij de node die    }
  489. { als parameter gegeven wordt (studentP).                           }
  490. {*******************************************************************}
  491. { PRE  : Type 'StudentP' moet gedefinieerd zijn.                    }
  492. { POST : Als de lijst niet leeg is, is de hele lijst zichtbaar      }
  493. {        vanaf 'StudentP'.                                          }
  494. {*******************************************************************}
  495. PROCEDURE ShowList(x,y : INTEGER;Head : StudentP);
  496. BEGIN
  497.   IF NOT(EmptyList(Head)) THEN
  498.     BEGIN
  499.       OutputStudent(x,y,Head);
  500.       x:=x+FormW+6*Dist;    
  501.       ShowList(x,y,Head^.Next);      { recursion }
  502.     END;
  503. END;
  504.  
  505. {*******************************************************************}  
  506. { DeleteNode(x,y);                                                  }
  507. { Verwijderd een node, nummer wordt afgevraagd.                     }
  508. {*******************************************************************}
  509. { PRE  : Er moet minstens 1 node in de list staan.                  }
  510. { POST : 1 element minder in de list.                               }  
  511. {*******************************************************************}  
  512. PROCEDURE DeleteNode(x,y : INTEGER);
  513. VAR
  514.   Nr       : INTEGER;
  515.   Position : StudentP;
  516.   BadNode  : StudentP;
  517.   Invoer   : string[35];
  518. BEGIN
  519.   Position:=StudentHead;
  520.   IF StudentHead^.Next=NIL THEN
  521.     DISPOSE(StudentHead)
  522.   ELSE    
  523.     BEGIN  
  524.       Invoer:='Remove Position number [1-';
  525.       Invoer:=ConCat(Invoer,CHR(48+ActiveNodes),']: ');
  526.       REPEAT                      { Read 1-ActiveNodes (max=5)      }
  527.         SetColor(Yellow);
  528.         SetFillStyle(SolidFill,Yellow);
  529.         DrawShadowBox(x-CX,y-CY,36*CX,3*CY);
  530.         SetColor(DarkGray);
  531.         OutTextXY(x,y,Invoer);
  532.         c:=readKey;
  533.       UNTIL ((c>#48)AND(c<=CHR(48+ActiveNodes+1)));
  534.       Nr:=ORD(c)-48;              { pos 2 =  insert NA pos 1        }  
  535.     IF Nr>1 THEN
  536.       BEGIN
  537.         GotoNodeNr(Nr-1,Position);
  538.         BadNode:=Position^.Next;
  539.         Position^.Next:=BadNode^.Next;                { Wipe Node   }
  540.         DISPOSE(BadNode);                             { free memory }    
  541.       END
  542.     ELSE 
  543.       BEGIN
  544.         BadNode:=StudentHead;
  545.         StudentHead:=BadNode^.Next;
  546.         DISPOSE(BadNode);
  547.       END;
  548.     END;
  549.     FixBar(x-CX,y-CY,x+36*CX+Dist,y+4*CY,Black,Black);
  550. END;
  551.  
  552. {*******************************************************************}
  553. { ClearList;                                                        }
  554. { Verwijderd de LinkedList uit het geheugen, reserved memory komt   }
  555. { nu vrij voor andere toepassingen.                                 }
  556. {*******************************************************************}
  557. { PRE  : De globale variable STUDENTHEAD moet bestaan.              }
  558. { POST : Een lege lijst.                                            }
  559. {*******************************************************************}
  560. PROCEDURE ClearList;
  561. VAR
  562.   Temp : StudentP;
  563. BEGIN
  564.   WHILE NOT(EmptyList(StudentHead)) DO
  565.   BEGIN
  566.     Temp:=StudentHead^.Next;
  567.     DISPOSE(StudentHead);
  568.     StudentHead:=Temp;
  569.   END;
  570. END;
  571.  
  572. {*******************************************************************}
  573. { ReadMenuKeys;                                                     }
  574. { Leest het toetsenbord voor de menu opties.                        }
  575. {*******************************************************************}
  576. { PRE  : Werkt met HeadInsert, PositionInsert, TailInsert en        }
  577. {         ShowList, deze moeten dus aanwezig zijn.                  }
  578. { POST : -                                                          }
  579. {*******************************************************************}
  580. PROCEDURE ReadMenuKeys;
  581. BEGIN
  582.   REPEAT 
  583.     c:=ReadKey;
  584.     CASE c OF
  585.       '1' : BEGIN
  586.                IF ActiveNodes<MaxNodes THEN
  587.                 BEGIN
  588.                   HeadInsert(20,80,StudentHead);      { 1 }
  589.                   ShowList(20,300,StudentHead);
  590.                   ActiveNodes:=SUCC(ActiveNodes);
  591.                 END;
  592.             END;
  593.       '2' : BEGIN
  594.                IF ActiveNodes<MaxNodes THEN
  595.                 BEGIN
  596.                   PositionInsert(20,80,StudentHead);  { 2 }
  597.                   ShowList(20,300,StudentHead);
  598.                   ActiveNodes:=SUCC(ActiveNodes);
  599.                 END;
  600.             END;
  601.       '3' : BEGIN
  602.               IF ActiveNodes<MaxNodes THEN
  603.                 BEGIN
  604.                   TailInsert(20,80,StudentHead);      { 3 }
  605.                   ActiveNodes:=SUCC(ActiveNodes);
  606.                   ShowList(20,300,StudentHead);
  607.                 END
  608.             END;
  609.       '4' : BEGIN
  610.               IF ActiveNodes>1 THEN
  611.                 BEGIN
  612.                   DeleteNode(20,80);                  { 4 }
  613.                   FixBar(20,300,650,450,Black,Black);
  614.                   ActiveNodes:=PRED(ActiveNodes);
  615.                 END
  616.               ELSE
  617.                 BEGIN
  618.                   ClearList;
  619.                   StudentHead:=NIL;
  620.                   FixBar(20,300,599,400,Black,Black);
  621.                   ActiveNodes:=0;
  622.                 END;
  623.               ShowList(20,300,StudentHead);
  624.             END;
  625.       '5' : exit;                                      { 5 }
  626.       END;
  627.   UNTIL FALSE;
  628. END;
  629.   
  630. {*******************************************************************}
  631. {******************************* MAIN ******************************}
  632. {*******************************************************************}
  633. BEGIN
  634.   ActiveNodes:=0;
  635.   StudentHead:=NIL;       { Nog lege lijst  }
  636.   OpenVGAScreen;          { VGAHi openen    }
  637.   IF VGAMode THEN         { VGAHi is nodig! }
  638.   BEGIN
  639.       DrawNodeIndex;      { Node nummering  }
  640.       DrawMenu(380,72);   { Menu tekenen    }
  641.       ReadMenuKeys;       { Menu afwachten  }
  642.       RestoreColors;      { Herstel kleuren }
  643.       CloseGraph;         { VGAHi Sluiten   }
  644.       ClearList;          { Release memory  }
  645.   END;
  646. END.                      { doei !          }
  647.  
  648.